package com.atguigu.ssyx.product.service.impl;

import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.product.mapper.CategoryMapper;
import com.atguigu.ssyx.product.service.CategoryService;
import com.atguigu.ssyx.vo.product.CategoryQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    //商品分类分页列表
	@Override
	public IPage<Category> selectPage(Page<Category> pageParam, CategoryQueryVo categoryQueryVo) {
		String name = categoryQueryVo.getName();
		LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
		if(!StringUtils.isEmpty(name)) {
			queryWrapper.like(Category::getName,name);
		}
		IPage<Category> categoryPage = baseMapper.selectPage(pageParam, queryWrapper);
		return categoryPage;
	}

    //查询所有商品分类
    @Override
    public List<Category> findAllList() {
		LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.orderByAsc(Category::getSort);
        return this.list(queryWrapper);
    }

}